﻿from bottle import route, run, static_file,request,template
import numpy as np
import sys
sys.path.append('../')
from board_fast import Robot,Point
@route('/static/<filename>')
def server_static(filename):
	return static_file(filename, root='./static')

@route('/genmove')
def genmove():	#web棋盘的原点是左下角，（列，行）
	color = request.query.color
	board = request.query.board
	board_array=board.split('_', -1 )
	board_array=[-1 if i =='O' else i for i in board_array]
	npboard=np.array(board_array)
	npboard[npboard=='.'] = 0
	npboard[npboard=='X'] = 1
	npboard=npboard.astype(int)
	npboard=np.flip(npboard.reshape(int(np.sqrt(len(npboard))),int(np.sqrt(len(npboard)))).T,axis=1)	#输入坐标转换在本地实现
	point=Robot.quickChooseMove(npboard,color=color)	#原点是左上角（行，列）
	return {'x':str(point.row),'y':str(point.col)}	#相应结果坐标转换在web端用js实现
run(host='localhost', port=8080,debug=True)
